package bacnetnetwork1;

import com.serotonin.bacnet4j.service.acknowledgement.*;
import com.serotonin.bacnet4j.service.confirmed.*;
import com.serotonin.bacnet4j.type.constructed.Address;
import com.serotonin.bacnet4j.type.enumerated.EngineeringUnits;
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
import com.serotonin.bacnet4j.type.enumerated.Segmentation;
import com.serotonin.bacnet4j.type.primitive.*;
import com.serotonin.bacnet4j.type.primitive.Boolean;

public class BACnetNetwork1 {    
    
    public static void main(String[] args){
        try {
            
            int bacnetNetworkPort=2116;
            String bacnetNetworkAddress="127.0.0.255";
            int bacnetNetworkNumber=1;
            BacNetNetwork bacnetNetwork=new BacNetNetwork(bacnetNetworkNumber,bacnetNetworkAddress);
            //String sensor1Address="127.0.0.11";
            //byte[] sensor1AddressBytes=new byte[] {(byte)127, (byte)0, (byte)0, (byte)11};
            //String sensor2Address="127.0.0.12";
            //byte[] sensor2AddressBytes=new byte[] {(byte)127, (byte)0, (byte)0, (byte)12};
            

            //Sensor sensor1=new Sensor(1, bacnetNetworkAddress, sensor1Address, bacnetNetworkPort, "Sensor 1", EngineeringUnits.degreesCelsius);   
            //Sensor sensor2=new Sensor(2, bacnetNetworkAddress, sensor2Address, bacnetNetworkPort, "Sensor 2", EngineeringUnits.degreesCelsius);
            //sensor2.setSensorValue(7.5); 
            //sensor1.setSensorValue(-3.6); 
            
            
            //ObjectIdentifier objId=sensor1.getObject("Sensor output").getId();
            //PropertyIdentifier propId=PropertyIdentifier.presentValue;            
            
  
            //AcknowledgementService result2=sensor2.send(new Address(sensor1AddressBytes,bacnetNetworkPort), null, 35, Segmentation.segmentedBoth, new ReadPropertyRequest(objId,propId));
            //System.out.println(((ReadPropertyAck)result2).getValue());
        
            //sensor2.send(new Address(sensor1AddressBytes,bacnetNetworkPort), null, 35, Segmentation.segmentedBoth, new WritePropertyRequest(objId, PropertyIdentifier.outOfService, null, new Boolean(true), new UnsignedInteger(5)));
            //AcknowledgementService result5=sensor2.send(new Address(sensor1AddressBytes,bacnetNetworkPort), null, 35, Segmentation.segmentedBoth, new ReadPropertyRequest(objId,PropertyIdentifier.outOfService));
            //System.out.println(((ReadPropertyAck)result5).getValue());
            
            //sensor1.terminate();
            //sensor2.terminate();

            //String controller1Address="127.0.0.201";
            //byte[] controller1AddressBytes=new byte[] {(byte)127, (byte)0, (byte)0, (byte)201};
            //Controller controller1=new Controller(201, bacnetNetworkAddress, controller1Address, bacnetNetworkPort, "Controller 1", EngineeringUnits.watts);

            //String ssm1Address="127.0.0.202";
            //byte[] ssm1AddressBytes=new byte[] {(byte)127, (byte)0, (byte)0, (byte)202};
            //SSM ssm1=new SSM(202, bacnetNetworkAddress, ssm1Address, bacnetNetworkPort, "SSM 1");

            //System.out.println(controller1AddressBytes);
            //Communicate communicate=new Communicate();
            
            //System.out.println(communicate.convertToBytes(controller1Address));

            //ObjectIdentifier objId2=controller1.getObject("Control parameter 1 value").getId();
            //PropertyIdentifier prid2=PropertyIdentifier.presentValue;
            //ssm1.send(new Address(controller1AddressBytes,bacnetNetworkPort), null, 35, Segmentation.segmentedBoth, new WritePropertyRequest(objId2, prid2, null, new Real(7.9f), new UnsignedInteger(1)));
            //AcknowledgementService result4=ssm1.send(new Address(controller1AddressBytes,bacnetNetworkPort), null, 35, Segmentation.segmentedBoth, new ReadPropertyRequest(objId2,prid2));
            //System.out.println(((ReadPropertyAck)result4).getValue());
            
            
            //controller1.terminate();
            //ssm1.terminate(); 
                    
            
        }
        catch (Exception e) {}             
        
        
    }
    
}
